#include <stdio.h>
#include <time.h>
#include <time.h>
#include <stdlib.h>
/* 函数声明 */
void getSeconds(unsigned long *par);

double getAverage(int *arr, int size);

/* 要生成和返回随机数的函数 */
int *getRandom()
{
  static int r[10];
  int i;

  /* 设置种子 */
  srand((unsigned)time(NULL));
  for (i = 0; i < 10; ++i)
  {
    r[i] = rand();
    printf("%d\n", r[i]);
  }

  return r;
}

int main()
{
  unsigned long sec;

  getSeconds(&sec);

  /* 输出实际值 */
  printf("Number of seconds: %ld\n", sec);

  /* 带有 5 个元素的整型数组  */
  int balance[5] = {1000, 2, 3, 17, 50};
  double avg;

  /* 传递一个指向数组的指针作为参数 */
  avg = getAverage(balance, 5);

  /* 输出返回值  */
  printf("Average value is: %f\n", avg);

  /* 一个指向整数的指针 */
  int *p;
  int i;

  p = getRandom();
  for (i = 0; i < 10; i++)
  {
    printf("*(p + [%d]) : %d\n", i, *(p + i));
  }

  return 0;
}

void getSeconds(unsigned long *par)
{
  /* 获取当前的秒数 */
  *par = time(NULL);
  return;
}

double getAverage(int *arr, int size)
{
  int i, sum = 0;
  double avg;

  for (i = 0; i < size; ++i)
  {
    sum += arr[i];
  }

  avg = (double)sum / size;

  return avg;
}